// 用户管理相关接口
import request from '@/utils/request'
import type { AllRoleResponseData, AllUserResponseData, SetRoleData, UserData } from './type'

enum API {
  // 分页获取所有用户
  ALLUSER_URL = "/admin/acl/user/",
  // 新增用户
  ADDUSER_URL = "/admin/acl/user/save",
  // 修改用户
  UPDATEUSER_URL = "/admin/acl/user/update",
  // 根据id删除用户
  DELETEUSERBYID_URL = "/admin/acl/user/remove/",
  // 批量删除用户
  DELETEUSERBYIDLIST_URL = "/admin/acl/user/batchRemove",
  // 获取全部角色
  ALLROLE_URL = "/admin/acl/user/toAssign/",
  // 设置角色
  SETROLE_URL = "/admin/acl/user/doAssignRole"
}

// 分页获取所有用户
export const reqAllUser = (currentPage: number, pageSize: number, username: string) =>
  request.get<any, AllUserResponseData>(API.ALLUSER_URL + `${currentPage}/${pageSize}?username=${username}`)
// 根据id删除用户
export const deleteUserById = (id: number) =>
  request.delete<any, any>(API.DELETEUSERBYID_URL + id)
// 批量删除用户
export const deleteUserByIdList = (idList: number[]) =>
  request.delete<any, any>(API.DELETEUSERBYIDLIST_URL, { data: idList })
// 新增用户或修改用户
export const addOrUpdateUser = (data: UserData) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, data)
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data)
  }
}
// 获取全部角色
export const reqAllRole = (id: number) =>
  request.get<any, AllRoleResponseData>(API.ALLROLE_URL + id)
// 设置角色
export const reqSetUserRole = (data: SetRoleData) =>
  request.post<any, any>(API.SETROLE_URL, data)
